/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset

* New variables
** Logaritm of taxes
gen log_tax = log(1+tot_taxes_usd)
label var log_tax "Log 1 + Tax (usd)"
** Month dummies for event study
local months "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
forvalues i = 1/12 {
	local x: word `i' of `months'
	forvalues year = 2017/2018 {
		gen `x'_`year' = cond(month_reg==`i' & year_reg==`year', 1, 0)
	}
}
drop Dec_2018

* Sample
gen date = mdy(month_reg, day_reg, year_reg)
keep if date>=20941 & date<=21335 // 6 month pre-post window (May 2017 - May 2018)
format date %td

* Globals
global months "May_2017 Jun_2017 Jul_2017 Aug_2017 Sep_2017 Oct_2017 Dec_2017 Jan_2018 Feb_2018 Mar_2018 Apr_2018 May_2018 Nov_2017"


* ---------
* Figure A6
* ---------

qui: reghdfe log_tax $months countryorig* max_twodigit* , absorb(insp_f key_dec) cluster(insp_f)

coefplot (, msymbol(o) mcolor(gs5) msize(small) ciopts(lcolor(gs5) lw(medium) lpattern(solid))), ///
	keep($months) order(May_2017 Jun_2017 Jul_2017 Aug_2017 Sep_2017 Oct_2017 Nov_2017 Dec_2017 Jan_2018 Feb_2018 Mar_2018 Apr_2018 May_2018) ///
	baselevels omitted vertical level(95) nokey ///
	yscale(range(-0.15(0.15)0.3)) ///
	ylabel(-0.15(0.15)0.3, angle(0) labsize(small) nogrid) ///
	yline(0, lpattern(dash) lwidth(thin) lcolor(gs8)) ///
	xlabel(1 "t-6"  2 "t-5" 3 "t-4" 4 "t-3" 5 "t-2" 6 "t-1" 7 "t" 8 "t+1" 9 "t+2" 10 "t+3" 11 "t+4" 12 "t+5" 13 "t+6" , nogrid angle(45)) ///
	xline(7, lpattern(shortdash) lwidth(vthin) lcolor(gs8)) ///
	name(Figure_A6, replace)
graph export "$figures\Figure_A6.eps", as(eps) replace
graph export "$figures\Figure_A6.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *